package com.dliu.javadesign.structure.decorator;

/**
 * @author yanglei
 * date 2021/3/30 18:13
 */
public class Computer {
    void listenMusic(){
        System.out.println("听音乐");
    }
}

abstract class ComputerDecorator {
    protected Computer computer;

    ComputerDecorator(Computer computer){
        this.computer = computer;
    }

    abstract void listenMusic();

}

class GameDecorator extends ComputerDecorator{

    public GameDecorator(Computer computer) {
        super(computer);
    }

    @Override
    void listenMusic() {
        computer.listenMusic();
        playGame();
    }

    public void playGame(){
        System.out.println("玩游戏");
    }


    public static void main(String[] args) {
        new Computer().listenMusic();
        System.out.println();
        GameDecorator gameDecorator = new GameDecorator(new Computer());
        gameDecorator.listenMusic();
    }
}
